/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.rcs.filesystem;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.rcs.folders.AbstractFolder;
import org.rcs.folders.VirtualItem;

/**
 *
 * @author pablo
 */
public class FolderItem extends AbstractFolder {

  private File dir;

  public FolderItem(File dir) {
    this.dir = dir;
  }

  @Override
  public String getName() {
    return dir.getName() ;
  }

  @Override
  public VirtualItem child(String childName) {
    File childFile = new File(dir, childName);

    if (childFile.isDirectory())
      return new FolderItem(childFile);
    else
      return new FileItem(childFile);
  }

  @Override
  public List<? extends VirtualItem> getChildren() {
    File[] children = dir.listFiles() ;
    List<VirtualItem> result = new ArrayList<VirtualItem>(children.length) ;

    for (File file : children) {
      if (file.isDirectory())
        result.add(new FolderItem(file));
      else
        result.add(new FileItem(file));
    }

    return Collections.unmodifiableList(result) ;
  }
}